//
//  BBHomeSearchVIew.m
//  BlockBrowser
//
//  Created by Mac on 2018/3/28.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "BBHomeSearchVIew.h"
@interface BBHomeSearchVIew()
@property(nonatomic, strong) STLabel                     *temLable;
@property(nonatomic, strong) STLabel                     *shiduLable;
@property(nonatomic, strong) STLabel                     *desLable;
@property(nonatomic, strong) STLabel                     *wheatherLable;
@property(nonatomic, strong) STLabel                     *pointLable;
@property(nonatomic, strong) STLabel                     *userLable;
@property(nonatomic, strong) STButton                     *searchButton;
@property(nonatomic, strong) STButton                     *userButton;
@end
@implementation BBHomeSearchVIew

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
- (void)setWeather:(BBWheatherModel *)weather{
    _weather = weather;
    if (weather.temp.length) {
        self.temLable.text = [NSString stringWithFormat:@"%@°C",
                              weather.temp];
        self.shiduLable.text = weather.fb;
        self.desLable.text = [NSString stringWithFormat:@"空气 %@",weather.desFb];
        self.wheatherLable.text = [NSString stringWithFormat:@"%@  %@",
                                   weather.city,weather.weather];
        [NSString lableAutoAdjustWitdhWithLabel:self.wheatherLable];
    }

}
- (void)setUserModel:(BBUserModel *)userModel{
    _userModel = userModel;
    if (userModel) {
//        [self.userButton sd_setImageWithURL:[NSURL URLWithString:userModel.avatar] forState:UIControlStateNormal];
        self.pointLable.text = userModel.coin.description;
       // self.userLable.text = userModel.nickname;
      //  [NSString lableAutoAdjustWitdhWithLabel:self.userLable];
      //  self.userLable.right = self.pointLable.right;
    }else{
        self.pointLable.text = @"0";
    }

}
#pragma mark --subView
- (void)configSubView{
    __weak typeof(self) weakSelf =  self;
    self.backgroundColor = TM_ThemeBackGroundColor;
    self.temLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 30, 80, 50)
                                                     text:@"20°C"
                                                textColor:[UIColor whiteColor]
                                                     font:28
                                              isSizetoFit:NO
                                     textAlignment:NSTextAlignmentLeft];
    [NSString lableAutoAdjustWitdhWithLabel:self.temLable];
    self.temLable.width = self.temLable.width + 10;
    [self addSubview:self.temLable];
    
    self.shiduLable = [[STLabel alloc] initWithFrame:CGRectMake(self.temLable.right, self.temLable.top, 24, 11)
                                                     text:@"81"
                                                textColor:[UIColor whiteColor]
                                                     font:10
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    self.shiduLable.backgroundColor = UIColorFromRGBA(0x56CDFB);
    self.shiduLable.layer.cornerRadius = 4;
    self.shiduLable.clipsToBounds = YES;
    [self addSubview:self.shiduLable];
    
    
    self.desLable = [[STLabel alloc] initWithFrame:CGRectMake(self.shiduLable.right + 5, self.temLable.top, 80, 20)
                                                text:@"----"
                                           textColor:[UIColor whiteColor]
                                                font:13
                                       isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];

    [self addSubview:self.desLable];
    self.shiduLable.centerY = self.desLable.centerY;
    
    self.wheatherLable = [[STLabel alloc] initWithFrame:CGRectMake(self.temLable.right, self.desLable.bottom, 100, 20)
                                              text:[NSString stringWithFormat:@"%@  %@",@"---",@"---"]
                                         textColor:[UIColor whiteColor]
                                              font:13
                                       isSizetoFit:NO
                                     textAlignment:NSTextAlignmentLeft];
    
    [self addSubview:self.wheatherLable];
    
    STButton * userButton = [[STButton alloc] initWithFrame:CGRectMake(0, self.temLable.top, 71, 61)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"小人"]];
    [self addSubview:userButton];
    self.userButton = userButton;
    [userButton setClicAction:^(UIButton *sender) {
        if(weakSelf.onSlectedUserHandle){
            weakSelf.onSlectedUserHandle(sender);
        }
    }];
    userButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    userButton.right = UIScreenWidth  -10;
    
    STLabel * userLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 80, 20)
                                                     text:@"当前数量"
                                                textColor:[UIColor whiteColor]
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentRight];
    [NSString lableAutoAdjustWitdhWithLabel:userLable];
    userLable.right = userButton.left - 10;
    userLable.centerY = self.desLable.centerY;
    self.userLable = userLable;
    [self addSubview:userLable];
    
    self.pointLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, userLable.width , 20)
                                                     text:@"0"
                                                textColor:[UIColor whiteColor]
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    self.pointLable.right = userLable.right;
    self.pointLable.top = userLable.bottom + 3;
    self.pointLable.backgroundColor = UIColorFromRGBA(0xFF5731);
    self.pointLable.layer.cornerRadius = 6;
    self.pointLable.clipsToBounds = YES;
    [self addSubview:self.pointLable];
    
   self.searchButton = [[STButton alloc] initWithFrame:CGRectMake(10, userButton.bottom + 10, UIScreenWidth - 20, 44)
                                                     title:@"搜索或者输入网址"
                                                titleColor:[UIColor whiteColor]
                                                 titleFont:14
                                              cornerRadius:4
                                           backgroundColor:UIColorFromRGBA(0xA3D1EE)
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"搜索1"]];
    self.searchButton.imageEdgeInsets = UIEdgeInsetsMake(0, 12, 0, 0);
    self.searchButton.titleEdgeInsets = UIEdgeInsetsMake(0, 12  + 12 , 0, 0);
    [self addSubview:self.searchButton];
    if ([BBThemeColorManger manger].type == BBThemeColorStyleBlacklook) {
        self.searchButton.backgroundColor = FlatGray;
    }
    
    [self.searchButton setClicAction:^(UIButton *sender) {
        if(weakSelf.onSlectedSearchHandle){
            weakSelf.onSlectedSearchHandle(sender);
        }
    }];
    
    self.height = self.searchButton.bottom  +30;
}
@end
